public class Person {
    private String name;
    private int age;
    //无参方法
    public Person() {
    }
    //有参方法
    public Person(String name, int age) throws  NullPointerException, AgeException {
        setName(name);
        setAge(age);
    }
    //name  get无参方法
    public String getName() {

        return name;
    }
    //name  get有参方法
    public void setName(String name) throws NullPointerException {
        if (name != null && !name.equals("")) {   //判断姓名为null或者""
            this.name = name;
        } else {
            throw new NullPointerException("输入的姓名不合理哦！");   //调用异常
        }
    }
    //name  age无参方法
    public int getAge() {
        return age;
    }
    //name  aet有参方法
    public void setAge(int age) throws AgeException {
        if (age > 18 && age < 150) {    //判断年龄小于18大于150
            this.age = age;
        } else {
            throw new AgeException("年龄不合理哦！");  //调用异常
        }
    }
//重写toString
    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
